
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>buddy伙伴算法 · book for nxos</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="nxos development team">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="heap.html" />
    
    
    <link rel="prev" href="mm.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://book-os.com" target="_blank" class="custom-link">bookos</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <span>
            
                    
                    NXOS文档中心
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" >
            
                <span>
            
                    
                    简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    NXOS 简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.2" >
            
                <span>
            
                    
                    快速上手
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.2.1" data-path="../../tutorial/quick-start.html">
            
                <a href="../../tutorial/quick-start.html">
            
                    
                    虚拟平台运行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2.2" data-path="../../tutorial/build-romdisk.html">
            
                <a href="../../tutorial/build-romdisk.html">
            
                    
                    构建romdisk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3" >
            
                <span>
            
                    
                    内核
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.1" data-path="../base/framework.html">
            
                <a href="../base/framework.html">
            
                    
                    整体框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.2" data-path="../base/start.html">
            
                <a href="../base/start.html">
            
                    
                    启动流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3" data-path="mm.html">
            
                <a href="mm.html">
            
                    
                    内存管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.3.3.1" data-path="buddy.html">
            
                <a href="buddy.html">
            
                    
                    buddy伙伴算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3.2" data-path="heap.html">
            
                <a href="heap.html">
            
                    
                    heapCache虚拟内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3.3" data-path="vmspace.html">
            
                <a href="vmspace.html">
            
                    
                    vmspace虚拟地址空间
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3.4" data-path="../sched/sched.html">
            
                <a href="../sched/sched.html">
            
                    
                    调度管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.4.1" data-path="../sched/thread.html">
            
                <a href="../sched/thread.html">
            
                    
                    线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.4.2" data-path="../sched/smp.html">
            
                <a href="../sched/smp.html">
            
                    
                    SMP多核调度
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3.5" data-path="../process/process.html">
            
                <a href="../process/process.html">
            
                    
                    进程管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.5.1" data-path="../process/syscall.html">
            
                <a href="../process/syscall.html">
            
                    
                    系统调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3.6" data-path="../interrupt/irq.html">
            
                <a href="../interrupt/irq.html">
            
                    
                    中断系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.6.1" data-path="../interrupt/delay_queue.html">
            
                <a href="../interrupt/delay_queue.html">
            
                    
                    延迟队列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3.7" data-path="../timer/timer.html">
            
                <a href="../timer/timer.html">
            
                    
                    定时器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.4" >
            
                <span>
            
                    
                    内核移植
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.4.1" data-path="../port/riscv/riscv.html">
            
                <a href="../port/riscv/riscv.html">
            
                    
                    riscv架构移植
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.5" >
            
                <span>
            
                    
                    平台支持
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.5.1" data-path="../platform/i386.html">
            
                <a href="../platform/i386.html">
            
                    
                    i386
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.2" data-path="../platform/qemu_riscv64.html">
            
                <a href="../platform/qemu_riscv64.html">
            
                    
                    qemu_riscv64
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.3" data-path="../platform/k210.html">
            
                <a href="../platform/k210.html">
            
                    
                    k210
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.4" data-path="../platform/d1.html">
            
                <a href="../platform/d1.html">
            
                    
                    d1-nezha
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.5.5" data-path="../platform/hifive_unmached.html">
            
                <a href="../platform/hifive_unmached.html">
            
                    
                    hifive unmached
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.6" >
            
                <span>
            
                    
                    用户态服务和驱动框架
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.6.1" data-path="../user/userver.html">
            
                <a href="../user/userver.html">
            
                    
                    用户态服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.2" data-path="../user/udriver.html">
            
                <a href="../user/udriver.html">
            
                    
                    用户态驱动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.6.3" data-path="../user/ubpf.html">
            
                <a href="../user/ubpf.html">
            
                    
                    UBPF
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.7" >
            
                <span>
            
                    
                    用户接口
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.7.1" data-path="../user/api.html">
            
                <a href="../user/api.html">
            
                    
                    API设计
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.8" >
            
                <span>
            
                    
                    编程开发
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.8.1" data-path="../../tutorial/code-style.html">
            
                <a href="../../tutorial/code-style.html">
            
                    
                    代码风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.2" data-path="../../tutorial/commit-rule.html">
            
                <a href="../../tutorial/commit-rule.html">
            
                    
                    提交规则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.3" data-path="../../tutorial/menuconfig.html">
            
                <a href="../../tutorial/menuconfig.html">
            
                    
                    菜单配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.4" data-path="../../tutorial/toolchains.html">
            
                <a href="../../tutorial/toolchains.html">
            
                    
                    工具链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.8.5" data-path="../../tutorial/utest.html">
            
                <a href="../../tutorial/utest.html">
            
                    
                    单元测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >buddy伙伴算法</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x7269;&#x7406;&#x5185;&#x5B58;&#x5206;&#x914D;&#x91CA;&#x653E;&#x7BA1;&#x7406;&#x4E4B;&#x4F19;&#x4F34;&#x7B97;&#x6CD5;buddy">&#x7269;&#x7406;&#x5185;&#x5B58;&#x5206;&#x914D;/&#x91CA;&#x653E;&#x7BA1;&#x7406;&#x4E4B;&#x4F19;&#x4F34;&#x7B97;&#x6CD5;(buddy)</h1>
<h2 id="&#x4E00;-&#x63CF;&#x8FF0;">&#x4E00;. &#x63CF;&#x8FF0;</h2>
<p>&#x5185;&#x5B58;&#x662F;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x8FD0;&#x884C;&#x7684;&#x6839;&#x57FA;&#xFF0C;&#x5904;&#x7406;&#x5668;&#x4ECE;&#x5185;&#x5B58;&#x4E2D;&#x53D6;&#x51FA;&#x6307;&#x4EE4;&#x6765;&#x6267;&#x884C;&#xFF0C;&#x5728;&#x8FDB;&#x5165;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E4B;&#x524D;&#xFF0C;&#x4E00;&#x822C;&#x4F1A;&#x6709;&#x5F15;&#x5BFC;&#x5668; <code>bootloader</code> &#x628A;&#x5185;&#x6838;&#x52A0;&#x8F7D;&#x5230;&#x5185;&#x6838;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x8DF3;&#x8F6C;&#x8FDB;&#x53BB;&#x6267;&#x884C;&#x3002;
&#x8FD9;&#x6837;&#x7684;&#x8BDD;&#xFF0C;&#x5185;&#x6838;&#x4E5F;&#x5C31;&#x5360;&#x7528;&#x4E86;&#x4E00;&#x90E8;&#x5206;&#x7684;&#x5185;&#x5B58;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x53BB;&#x7BA1;&#x7406;&#x54EA;&#x90E8;&#x5206;&#x5185;&#x5B58;&#x5462;&#xFF1F;
&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7BA1;&#x7406;&#x7684;&#x7269;&#x7406;&#x5185;&#x5B58;&#x662F;&#x9664;&#x4E86;&#x4FDD;&#x7559;&#x5730;&#x5740;&#x548C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x5360;&#x7528;&#x4EE5;&#x5916;&#x7684;&#x7A7A;&#x95F2;&#x7684;&#x5185;&#x5B58;&#xFF0C;&#x8FD9;&#x90E8;&#x5206;&#x5185;&#x5B58;&#x5C31;&#x662F;&#x9700;&#x8981;&#x5728;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x8FD0;&#x884C;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x8FDB;&#x884C;&#x9759;&#x6001;/&#x52A8;&#x6001;&#x5206;&#x914D;&#x7684;&#x5185;&#x5B58;&#x3002;
<code>nxos</code> &#x5728; <code>qemu</code> &#x7684; <code>riscv64</code> &#x865A;&#x62DF;&#x5E73;&#x53F0;&#x4E2D;&#xFF0C;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x5982;&#x4E0B;:</p>
<pre><code class="lang-c"><span class="hljs-comment">/**
 * Physical memory layout:
 *
 * +------------------------+ &lt;- MAX PHY SIZE (TOP to 4GB)
 * | L3 PAGES               |
 * +------------------------+ &lt;- KERNEL PAGES (TOP to 2GB + 128MB)
 * | L3(K) &amp; L0/1/2  PAGES  |
 * +------------------------+ &lt;- 0x82000000 (2GB + 32MB)
 * | KERNEL                 |
 * +------------------------+ &lt;- 0x80200000 (2GB + 2MB)
 * | OPENSBI                |
 * +------------------------+ &lt;- 0x80000000 (2GB)
 * | MMIO/UNMAPPED          |
 * +------------------------+ &lt;- 0x00000000
 */</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7BA1;&#x7406;&#x7684;&#x5185;&#x5B58;&#x5C31;&#x662F; <code>0x82000000-TOP</code> &#x4E4B;&#x95F4;&#x7684;&#x8FD9;&#x90E8;&#x5206;&#x5185;&#x5B58;&#x3002;&#x7B80;&#x5355;&#x7684;&#x8BF4;&#x5C31;&#x662F;&#x5BF9;&#x4E00;&#x6BB5;&#x6216;&#x8005;&#x591A;&#x6BB5;&#x7A7A;&#x95F2;&#x7684;&#x5185;&#x5B58;&#x5730;&#x5740;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#xFF0C;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x5206;&#x914D;&#x4E0E;&#x91CA;&#x653E;&#xFF0C;&#x8BA9;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x53BB;&#x4F7F;&#x7528;&#x3002;</p>
<h2 id="&#x4E8C;-&#x539F;&#x7406;">&#x4E8C;. &#x539F;&#x7406;</h2>
<p>&#x5728; <code>nxos</code> &#x4E2D;&#x4F7F;&#x7528; <code>buddy</code> &#x4F19;&#x4F34;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x7B97;&#x6CD5;&#x3002;&#x4E3A;&#x4E86;&#x4FBF;&#x4E8E;&#x9875;&#x9762;&#x7684;&#x7EF4;&#x62A4;&#xFF0C;&#x5C06;&#x591A;&#x4E2A;&#x9875;&#x9762;&#x7EC4;&#x6210;&#x5185;&#x5B58;&#x5757;&#xFF0C;&#x6BCF;&#x4E2A;&#x5185;&#x5B58;&#x5757;&#x90FD;&#x6709;2&#x7684;&#x65B9;&#x5E42;&#x4E2A;&#x9875;&#xFF0C;&#x65B9;&#x5E42;&#x7684;&#x6307;&#x6570;&#x88AB;&#x79F0;&#x4E3A;&#x9636;&#x3002;&#x5728;&#x64CD;&#x4F5C;&#x5185;&#x5B58;&#x65F6;&#xFF0C;&#x7ECF;&#x5E38;&#x5C06;&#x8FD9;&#x4E9B;&#x5185;&#x5B58;&#x5757;&#x5206;&#x6210;&#x5927;&#x5C0F;&#x76F8;&#x7B49;&#x7684;&#x4E24;&#x4E2A;&#x5757;&#xFF0C;&#x5206;&#x6210;&#x7684;&#x4E24;&#x4E2A;&#x5185;&#x5B58;&#x5757;&#x88AB;&#x79F0;&#x4E3A;&#x4F19;&#x4F34;&#x5757;&#xFF0C;&#x91C7;&#x7528;&#x4E00;&#x4F4D;&#x4E8C;&#x8FDB;&#x5236;&#x6570;&#x6765;&#x8868;&#x793A;&#x5B83;&#x4EEC;&#x7684;&#x4F19;&#x4F34;&#x5173;&#x7CFB;&#x3002;&#x5F53;&#x8FD9;&#x4E2A;&#x4F4D;&#x4E3A;1&#xFF0C;&#x8868;&#x793A;&#x5176;&#x4E2D;&#x4E00;&#x5757;&#x5728;&#x4F7F;&#x7528;&#xFF1B;&#x5F53;&#x8FD9;&#x4E2A;&#x4F4D;&#x4E3A;0&#xFF0C;&#x8868;&#x793A;&#x4E24;&#x4E2A;&#x9875;&#x9762;&#x5757;&#x90FD;&#x7A7A;&#x95F2;&#x6216;&#x8005;&#x90FD;&#x5728;&#x4F7F;&#x7528;&#x3002;&#x7CFB;&#x7EDF;&#x6839;&#x636E;&#x8BE5;&#x4F4D;&#x4E3A;0&#x6216;&#x4F4D;&#x4E3A;1&#x6765;&#x51B3;&#x5B9A;&#x662F;&#x5426;&#x4F7F;&#x7528;&#x6216;&#x8005;&#x5206;&#x914D;&#x8BE5;&#x9875;&#x9762;&#x5757;&#x3002;&#x7CFB;&#x7EDF;&#x6BCF;&#x6B21;&#x5206;&#x914D;&#x548C;&#x56DE;&#x6536;&#x4F19;&#x4F34;&#x5757;&#x65F6;&#x90FD;&#x8981;&#x5BF9;&#x5B83;&#x4EEC;&#x7684;&#x4F19;&#x4F34;&#x4F4D;&#x8DDF;1&#x8FDB;&#x884C;&#x5F02;&#x6216;&#x8FD0;&#x7B97;&#x3002;&#x6240;&#x8C13;&#x5F02;&#x6216;&#x662F;&#x6307;&#x521A;&#x5F00;&#x59CB;&#x65F6;&#xFF0C;&#x4E24;&#x4E2A;&#x4F19;&#x4F34;&#x5757;&#x90FD;&#x7A7A;&#x95F2;&#xFF0C;&#x5B83;&#x4EEC;&#x7684;&#x4F19;&#x4F34;&#x4F4D;&#x4E3A;0&#xFF0C;&#x5982;&#x679C;&#x5176;&#x4E2D;&#x4E00;&#x5757;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x5F02;&#x6216;&#x540E;&#x5F97;1&#xFF1B;&#x5982;&#x679C;&#x53E6;&#x4E00;&#x5757;&#x4E5F;&#x88AB;&#x4F7F;&#x7528;&#xFF0C;&#x5F02;&#x6216;&#x540E;&#x5F97;0&#xFF1B;&#x5982;&#x679C;&#x524D;&#x9762;&#x4E00;&#x5757;&#x56DE;&#x6536;&#x4E86;&#x5F02;&#x6216;&#x540E;&#x5F97;1&#xFF1B;&#x5982;&#x679C;&#x53E6;&#x4E00;&#x5757;&#x4E5F;&#x56DE;&#x6536;&#x4E86;&#x5F02;&#x6216;&#x540E;&#x5F97;0&#x3002;</p>
<p>&#x7B97;&#x6CD5;&#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x4E0D;&#x8FDB;&#x884C;&#x8BB2;&#x89E3;&#xFF0C;&#x9664;&#x975E;&#x4F60;&#x9700;&#x8981;&#x6765;&#x4F18;&#x5316;&#x8FD9;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#xFF0C;&#x624D;&#x9700;&#x8981;&#x4E86;&#x89E3;&#x5230;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x662F;&#x53BB;&#x4F7F;&#x7528;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x53EA;&#x9700;&#x8981;&#x719F;&#x6089;&#x63A5;&#x53E3;&#x5373;&#x53EF;&#x3002;</p>
<ul>
<li><p>&#x4F18;&#x7F3A;&#x70B9;</p>
</li>
<li><p>&#x5C3D;&#x7BA1;&#x4F19;&#x4F34;&#x5185;&#x5B58;&#x7B97;&#x6CD5;&#x5728;&#x5185;&#x5B58;&#x788E;&#x7247;&#x95EE;&#x9898;&#x4E0A;&#x5DF2;&#x7ECF;&#x505A;&#x7684;&#x76F8;&#x5F53;&#x51FA;&#x8272;&#xFF0C;&#x4F46;&#x662F;&#x8BE5;&#x7B97;&#x6CD5;&#x4E2D;&#xFF0C;&#x4E00;&#x4E2A;&#x5F88;&#x5C0F;&#x7684;&#x5757;&#x5F80;&#x5F80;&#x4F1A;&#x963B;&#x788D;&#x4E00;&#x4E2A;&#x5927;&#x5757;&#x7684;&#x5408;&#x5E76;&#xFF0C;&#x4E00;&#x4E2A;&#x7CFB;&#x7EDF;&#x4E2D;&#xFF0C;&#x5BF9;&#x5185;&#x5B58;&#x5757;&#x7684;&#x5206;&#x914D;&#xFF0C;&#x5927;&#x5C0F;&#x662F;&#x968F;&#x673A;&#x7684;&#xFF0C;&#x4E00;&#x7247;&#x5185;&#x5B58;&#x4E2D;&#x4EC5;&#x4E00;&#x4E2A;&#x5C0F;&#x7684;&#x5185;&#x5B58;&#x5757;&#x6CA1;&#x6709;&#x91CA;&#x653E;&#xFF0C;&#x65C1;&#x8FB9;&#x4E24;&#x4E2A;&#x5927;&#x7684;&#x5C31;&#x4E0D;&#x80FD;&#x5408;&#x5E76;&#x3002;</p>
</li>
<li><p>&#x7B97;&#x6CD5;&#x4E2D;&#x6709;&#x4E00;&#x5B9A;&#x7684;&#x6D6A;&#x8D39;&#x73B0;&#x8C61;&#xFF0C;&#x4F19;&#x4F34;&#x7B97;&#x6CD5;&#x662F;&#x6309;2&#x7684;&#x5E42;&#x6B21;&#x65B9;&#x5927;&#x5C0F;&#x8FDB;&#x884C;&#x5206;&#x914D;&#x5185;&#x5B58;&#x5757;&#xFF0C;&#x5F53;&#x7136;&#x8FD9;&#x6837;&#x505A;&#x662F;&#x6709;&#x539F;&#x56E0;&#x7684;&#xFF0C;&#x5373;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x628A;&#x5927;&#x7684;&#x5185;&#x5B58;&#x5757;&#x62C6;&#x7684;&#x592A;&#x788E;&#xFF0C;&#x66F4;&#x91CD;&#x8981;&#x7684;&#x662F;&#x4F7F;&#x5206;&#x914D;&#x548C;&#x91CA;&#x653E;&#x8FC7;&#x7A0B;&#x8FC5;&#x901F;&#x3002;&#x4F46;&#x662F;&#x4ED6;&#x4E5F;&#x5E26;&#x6765;&#x4E86;&#x4E0D;&#x5229;&#x7684;&#x4E00;&#x9762;&#xFF0C;&#x5982;&#x679C;&#x6240;&#x9700;&#x5185;&#x5B58;&#x5927;&#x5C0F;&#x4E0D;&#x662F;2&#x7684;&#x5E42;&#x6B21;&#x65B9;&#xFF0C;&#x5C31;&#x4F1A;&#x6709;&#x90E8;&#x5206;&#x9875;&#x9762;&#x6D6A;&#x8D39;&#x3002;&#x6709;&#x65F6;&#x8FD8;&#x5F88;&#x4E25;&#x91CD;&#x3002;&#x6BD4;&#x5982;&#x539F;&#x6765;&#x662F;1024&#x4E2A;&#x5757;&#xFF0C;&#x7533;&#x8BF7;&#x4E86;16&#x4E2A;&#x5757;&#xFF0C;&#x518D;&#x7533;&#x8BF7;600&#x4E2A;&#x5757;&#x5C31;&#x7533;&#x8BF7;&#x4E0D;&#x5230;&#x4E86;&#xFF0C;&#x56E0;&#x4E3A;&#x5DF2;&#x7ECF;&#x88AB;&#x5206;&#x5272;&#x4E86;&#x3002;</p>
</li>
<li><p>&#x53E6;&#x5916;&#x62C6;&#x5206;&#x548C;&#x5408;&#x5E76;&#x6D89;&#x53CA;&#x5230; &#x8F83;&#x591A;&#x7684;&#x94FE;&#x8868;&#x548C;&#x4F4D;&#x56FE;&#x64CD;&#x4F5C;&#xFF0C;&#x5F00;&#x9500;&#x8FD8;&#x662F;&#x6BD4;&#x8F83;&#x5927;&#x7684;&#x3002;</p>
</li>
</ul>
<h2 id="&#x4E09;&#x3001;&#x6846;&#x67B6;&#x56FE;">&#x4E09;&#x3001;&#x6846;&#x67B6;&#x56FE;</h2>
<p><img src="figures/buddy.png" alt="&#x6846;&#x67B6;&#x56FE;"></p>
<h2 id="&#x56DB;-&#x63A5;&#x53E3;">&#x56DB;. &#x63A5;&#x53E3;</h2>
<p>&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x6700;&#x57FA;&#x672C;&#x7684;&#x63A5;&#x53E3;&#x5C31;&#x662F;&#x5206;&#x914D;&#x548C;&#x91CA;&#x653E;&#x3002;&#x4E3A;&#x4E86;&#x80FD;&#x591F;&#x652F;&#x6301;&#x5206;&#x9875;&#x673A;&#x5236;&#xFF0C;&#x4E3A;&#x9875;&#x8868;&#x6620;&#x5C04;&#x63D0;&#x4F9B;&#x5185;&#x5B58;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5C06;&#x5185;&#x5B58;&#x5206;&#x4E3A;&#x9875;&#x9762;&#x5927;&#x5C0F;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x4F1A;&#x6BD4;&#x8F83;&#x5408;&#x9002;&#x3002;
&#x6240;&#x4EE5;&#xFF0C;&#x5206;&#x914D;&#x548C;&#x91CA;&#x653E;&#x7684;&#x57FA;&#x7840;&#x5355;&#x4F4D;&#x5C31;&#x662F;&#x9875;&#x9762;&#x3002;&#x901A;&#x5E38;&#x6765;&#x8BF4;&#xFF0C;&#x9875;&#x9762;&#x5927;&#x5C0F;&#x662F;4kb&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x66F4;&#x5927;&#xFF0C;&#x4F46;&#x662F;&#x7531;&#x4E8E;4kb&#x5728;32&#x4F4D;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E2D;&#x53EF;&#x4EE5;&#x5F88;&#x597D;&#x5730;&#x5BF9;4GB&#x5185;&#x5B58;&#x8FDB;&#x884C;&#x6620;&#x5C04;&#xFF0C;
&#x6240;&#x4EE5;&#xFF0C;4kb&#x4E5F;&#x5C31;&#x5EF6;&#x7EED;&#x5230;64&#x4F4D;&#x7CFB;&#x7EDF;&#x4E86;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;4kb&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x7684;&#x5927;&#x5C0F;&#x3002;</p>
<p>&#x5728;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; <code>buddy system</code> &#x6765;&#x7BA1;&#x7406;&#x4E00;&#x6BB5;&#x8FDE;&#x7EED;&#x7684;&#x7269;&#x7406;&#x5185;&#x5B58;&#x3002;&#x9700;&#x8981;&#x5236;&#x5B9A;&#x7269;&#x7406;&#x5185;&#x5B58;&#x5730;&#x5740;&#x548C;&#x7269;&#x7406;&#x5185;&#x5B58;&#x5927;&#x5C0F;&#x3002;</p>
<pre><code class="lang-c"><span class="hljs-function">NX_BuddySystem* <span class="hljs-title">NX_BuddyCreate</span><span class="hljs-params">(<span class="hljs-keyword">void</span> *mem, NX_Size size)</span></span>;
</code></pre>
<p>&#x9875;&#x9762;&#x5206;&#x914D;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x4ECE;&#x4E00;&#x4E2A; <code>buddy system</code> &#x91CC;&#x9762;&#x5206;&#x914D; <code>count</code> &#x4E2A;&#x9875;&#x9762;&#x3002;&#x5728;MMU&#x6620;&#x5C04;&#x548C;&#x865A;&#x62DF;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x5668;&#x4E2D;&#x4F1A;&#x4F7F;&#x7528;&#x5230;&#x3002;
&#x6709;&#x5FC5;&#x8981;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E5F;&#x4F1A;&#x5728;&#x9700;&#x8981;&#x7269;&#x7406;&#x5185;&#x5B58;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x8BE5;&#x5206;&#x914D;&#x3002;</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">void</span> *<span class="hljs-title">NX_BuddyAllocPage</span><span class="hljs-params">(NX_BuddySystem* system, NX_Size count)</span></span>;
</code></pre>
<p>&#x9875;&#x9762;&#x91CA;&#x653E;&#x51FD;&#x6570;&#xFF0C;&#x4ECE;&#x4E00;&#x4E2A; <code>buddy system</code> &#x91CC;&#x9762;&#x91CA;&#x653E;&#x67D0;&#x4E2A;&#x5730;&#x5740;&#x6307;&#x9488;&#xFF0C;&#x8BE5;&#x6307;&#x9488;&#x5FC5;&#x987B;&#x662F;&#x4ECE; <code>buddy</code> &#x7CFB;&#x7EDF;&#x4E2D;&#x5206;&#x914D;&#x7684;&#x9875;&#x9762;&#x3002;
&#x5728;&#x91CA;&#x653E;&#x9875;&#x9762;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9700;&#x8981;&#x5F15;&#x7528;&#x8BA1;&#x6570;&#x4E3A;0&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x624D;&#x4F1A;&#x53BB;&#x6B63;&#x5728;&#x91CA;&#x653E;&#x8FD9;&#x4E2A;&#x9875;&#x9762;&#x3002;</p>
<pre><code class="lang-c"><span class="hljs-function">NX_Error <span class="hljs-title">NX_BuddyFreePage</span><span class="hljs-params">(NX_BuddySystem* system, <span class="hljs-keyword">void</span> *ptr)</span></span>;
</code></pre>
<p>&#x6709;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5F53;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x88AB;&#x591A;&#x6B21;&#x4F7F;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x9700;&#x8981;&#x53BB;&#x589E;&#x52A0;&#x5176;&#x5F15;&#x7528;&#x8BA1;&#x6570;&#xFF0C;&#x6765;&#x907F;&#x514D;&#x88AB;&#x91CA;&#x653E;&#x6389;&#x3002;</p>
<pre><code class="lang-c"><span class="hljs-function">NX_Error <span class="hljs-title">NX_BuddyIncreasePage</span><span class="hljs-params">(NX_BuddySystem* system, <span class="hljs-keyword">void</span> *ptr)</span></span>;
</code></pre>
<p>&#x5728;&#x4F7F;&#x7528;&#x9875;&#x9762;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x9700;&#x8981;&#x628A;&#x4E00;&#x4E2A;&#x5730;&#x7816;&#x8F6C;&#x6362;&#x6210;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x9875;&#x9762;&#x7ED3;&#x6784;&#xFF0C;&#x6765;&#x8BBF;&#x95EE;&#x8BE5;&#x7ED3;&#x6784;&#x91CC;&#x9762;&#x7684;&#x6210;&#x5458;&#xFF0C;&#x8FD9;&#x5728;&#x865A;&#x62DF;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x5668;
&#x5B9E;&#x73B0;&#x7684;&#x65F6;&#x5019;&#x6709;&#x4F7F;&#x7528;&#x5230;&#x3002;</p>
<pre><code class="lang-c"><span class="hljs-function">NX_Page* <span class="hljs-title">NX_PageFromPtr</span><span class="hljs-params">(NX_BuddySystem* system, <span class="hljs-keyword">void</span> *ptr)</span></span>;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mm.html" class="navigation navigation-prev " aria-label="Previous page: 内存管理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="heap.html" class="navigation navigation-next " aria-label="Next page: heapCache虚拟内存管理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"buddy伙伴算法","level":"1.1.3.3.1","depth":4,"next":{"title":"heapCache虚拟内存管理","level":"1.1.3.3.2","depth":4,"path":"programing-manual/mm/heap.md","ref":"programing-manual/mm/heap.md","articles":[]},"previous":{"title":"内存管理","level":"1.1.3.3","depth":3,"path":"programing-manual/mm/mm.md","ref":"programing-manual/mm/mm.md","articles":[{"title":"buddy伙伴算法","level":"1.1.3.3.1","depth":4,"path":"programing-manual/mm/buddy.md","ref":"programing-manual/mm/buddy.md","articles":[]},{"title":"heapCache虚拟内存管理","level":"1.1.3.3.2","depth":4,"path":"programing-manual/mm/heap.md","ref":"programing-manual/mm/heap.md","articles":[]},{"title":"vmspace虚拟地址空间","level":"1.1.3.3.3","depth":4,"path":"programing-manual/mm/vmspace.md","ref":"programing-manual/mm/vmspace.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy BookOS-developers 2022","modify_label":"修订时间：","modify_format":"YYYY-MM-DD"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"nxos development team","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"book for nxos","language":"zh-hans","links":{"sidebar":{"bookos":"http://book-os.com"}},"gitbook":"3.2.3","description":"document for nxos kernel"},"file":{"path":"programing-manual/mm/buddy.md","mtime":"2022-05-03T18:23:23.478Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-06-21T14:02:23.265Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

